<?php
/**
*	模块：userinfo.人员档案
*	说明：自定义区域内可写你想要的代码
*	来源：流程模块→表单元素管理→[模块.人员档案]→生成列表页
*/
defined('HOST') or die ('not access');
?>
<script>
$(document).ready(function(){

	var deptname = '';
	var url = js.getajaxurl('deptuserjson','dept','system',{});
	$.get(url,function(ret){
		let o = JSON.parse(ret).data.deptjson;
		let d = js.decode(o);
		at.loadData(d);
		setSelectOptions(d[0])
	})
	

	// $db 	= m('kqxxsj');
	// $where = "pid='$pid' and `dt`='$dt'";
	// $db->rows($where)
	// $db->rows("`uid`='$uid' and `dkdt`='$dkdt'")

	// $where = "`plx`='$plx' and `receid`='$receid' and `dt`='$dt'";
	// $db->update('`mid`='.$mid.',`type`='.$type.'', $where)

	// $db		= m('kqsjgz');
	// $menu	= $db->getall("`pid`='$pid' order by `sort`",'*');

	// $db->getall('pid=0','id,name','`id`');


	// if($db->rows($where)==0)$db->insert("pid='$pid',`dt`='$dt'");


	// $where = "pid='$pid' and `dt`='$dt'";
	// $db->delete($where);

	// return array('rows'=>$rows,'totalstr'=> $str);


	// $num = $this->get('num');
	// $arr = m('option')->getdata($num);
	// echo json_encode($arr);
// ----
	// js.decode(js.getoption('groupjson'))

	// $db->getone($id);

	// $rs['stotal']	= $db->rows("`pid`='$sid'");
	// $this->rows[] = $rs;

	var setSelectOptions = function(d){
		deptname = d.name;
		$("#titlebar").text(d.name+"考勤人员设置：")
		$("#titlebar").css({"font-weight":"bold", 'margin-bottom': '5px', 'font-size': '18px'});
		$.get(js.getajaxurl('getdeptuser','kaoqin','main', {deptname:d.name}), function(ret){
			let o = JSON.parse(ret).data;
			// js.setselectdata(get('viewuserinfoa'),[],'id');
			// get('viewuserinfoa').value = xusnid;
			$("#viewuserinfoa option:not(:first-child)").remove();
			js.setselectdata(get('viewuserinfoa'),o,'id');
			let vals = [];
			o.forEach(element => {
				if(element.attendance == 1) {
					vals.push(element.id);
				}
			});
			$("#viewuserinfoa").val(vals);

			$('#viewuserinfoa').find("option:selected").css({"font-weight":"bold", "background": "#b3d7ff", "border-radius": "30px"});
			$('#viewuserinfoa option').css({"padding": "5px 20px", "border-radius": "30px"});

		});
	}

	



	$("#viewuserinfoa").change(function() {
		var selectedValue = $(this).val();
		$.get(js.getajaxurl('setattendance','kaoqin','main', {attendance: selectedValue, deptname: deptname}), function(ret){
			// let o = JSON.parse(ret).data;
			console.log(ret)
			js.msg('success','设置成功');
		});
		$('#viewuserinfoa option').css({"font-weight":"", "background": "white"});
		$(this).find("option:selected").css({"font-weight":"bold", "background": "#b3d7ff"});
	});

	// 监听 select 元素的 change 事件，并应用样式
	// $("#viewuserinfoa").on("change", function() {

	// 	$(this).find("option").each(function() {
	// 		if ($(this).is(":selected")) {
	// 			$(this).css({"font-weight": "bold", "background": "#b3d7ff", "padding": "10px"});
	// 		} else {
	// 			$(this).css({"font-weight": "", "background": "", "padding": "10px"});
	// 		}
	// 	});

	// });
	


	var at = $('#optionview_{rand}').bootstree({
		url:false,autoLoad:false,
		columns:[{
			text:'组织结构',dataIndex:'name',align:'left',xtype:'treecolumn'
		}],
		itemclick:function(d){
			// c.setparams({'deptid':d.id}, true);
			setSelectOptions(d)
		},
		load:function(d){
			console.log(d, 3333)
		},
	});
	$('#optionview_{rand}').css('height',''+(viewheight-25)+'px');
	$('#viewuserinfoa').css('height',''+(viewheight-300)+'px');


});
</script>
<!--SCRIPTend-->
<!--HTMLstart-->
<div style="display: flex;">
	<div style="margin-right: 10px;width: 210px;">
		<div id="optionview_{rand}" style="height:300px;overflow:auto;"></div>
	</div>
	<div style="flex: 1;">
		<div  style="margin: 50px; padding: 30px;" >
			<div id="titlebar"></div>
			<select id="viewuserinfoa" style="width:100%;"  size="15" multiple></select>
		</div>
	</div>
</div>
<!--HTMLend-->